/*
 * Copyright (C) 2013 The original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy
 * of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.zapta.apps.maniana.editors;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zapta.apps.maniana.R;
import com.zapta.apps.maniana.annotations.MainActivityScope;
import com.zapta.apps.maniana.model.ItemColor;
import com.zapta.apps.maniana.util.BitmapUtil;
import com.zapta.apps.maniana.util.DisplayUtil;

/*
**
** @author Elliott Mitchell
**/
@MainActivityScope
abstract public class ItemTextEditorExtra extends Fragment
implements AdapterView.OnItemSelectedListener {

	private class ColorAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			return ItemColor.values().length; // .size();
		}

		@Override
		public ItemColor getItem(int position) {
			return ItemColor.values()[position];
		}

		@Override
		public long getItemId(int position) {
			// We use the position as ID
			return position;
		}

		public View getView(final int position, View view, ViewGroup
parent) {
			// Create a new View, if needed
			if (view == null) {
				final LayoutInflater inflater=(LayoutInflater)
getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				view=inflater.inflate(R.layout.editor_color_entry,
parent, false);
			}


			// Get the density value
			final float density=DisplayUtil.
getDensity(getActivity());

			// Set color
			final ItemColor color=getItem(position);
			final ImageView imageView=(ImageView)
view.findViewById(R.id.editor_color_image);
			imageView.setImageBitmap(BitmapUtil.
getColorPreviewBitmap(color.getColor(0xff666666), Color.GRAY, density));

			// Set text
			final TextView textView=(TextView)
view.findViewById(R.id.editor_color_text);
			textView.setText(getActivity().
getString(parent.getClass()!=android.widget.Spinner.class?color.nameResourceId:
getSpinnerTextId(parent.getId())));

			return view;
		}
	}
	ColorAdapter mColors;

	@Override
	public View onCreateView(LayoutInflater inflator, ViewGroup container,
Bundle state) {
		mColors=new ColorAdapter();

		return null;
	}

	abstract int getSpinnerTextId(int id);

	public void onNothingSelected(AdapterView<?> parent) {
		// do nothing
	}
}

